"""
表达式
"""
from operator import add, mul
from math import pi

# 通过这样的方式，就将area函数的返回值将radius的值绑定起来了，
# radius改变之后，即使area不加参数，返回值也会改变
radius = 10


def square(x):
    return mul(x, x)


def sum_square(x, y):
    """返回平方和"""
    return add(square(x), square(y))


print(sum_square(10, 2))
print(square(10))


def area():
    return pi * radius * radius


print(area())
radius = 20
print(area())


def pressure(v, t, n):
    """理想气体状态方程 Compute the pressure in pascals of an ideal gas.

    Applies the ideal gas law: https://en.wikipedia.org/wiki/Ideal_gas_law

    v -- volume of gas, in cubic meters
    t -- absolute temperature in degrees kelvin
    n -- particles of gas
    """
    k = 1.38e-23  # Boltzmann's constant
    return n * k * t / v


# 使用help函数来查看当前函数的作用
help(pressure)

"""
None
1
2
None None
"""
print(None)
print(print(1), print(2))  # 因为print的返回值为None所以会打印两个None

"""
纯函数
"""

def pure_function(x, y):
    """纯函数示例：给定相同输入总是返回相同输出且没有副作用"""
    return x * y + 2


def impure_function():
    """非纯函数示例：依赖外部状态且可能有副作用"""
    global radius
    radius += 1  # 修改外部状态
    print(f"Radius is now {radius}")  # 产生副作用
    return radius

# 纯函数调用示例
print(pure_function(3, 4))  # 总是返回14

# 非纯函数调用示例
print(impure_function())  # 结果取决于外部状态且会产生副作用